import React, { useEffect, useState } from 'react'

export default function Count() {
  const [count, setCount] = useState(10)

  useEffect(() => {
    // 副作用回调函数
    const timer = setInterval(() => {
      console.log(1)
      setCount((count) => count - 1)
    }, 1000)
    return () => {
      console.log('清理函数执行啦~~')
      // 清理函数
      clearInterval(timer)
    }
  }, [])

  return <div>Count: {count}</div>
}
